package com.example.doudou.demos.controller;

import com.example.common.domain.R;
import com.example.doudou.demos.pojo.UserLogRecord;
import com.example.doudou.demos.service.ProductsService;
import com.example.doudou.demos.service.UserLogRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author fangtao
 * @projectName doudou
 * @date 2025/5/30
 * @description 多线程控制层
 */

@RestController
@Slf4j
@Api(tags = "多线程控制层")
public class MultithreadController {

    @Autowired
    private UserLogRecordService userLogRecordService;

    @Autowired
    private ProductsService productsService;

    /**
     * 获取操作日志记录-测试多线程
     */
    @ApiOperation(value = "获取操作日志记录-测试多线程", notes = "获取操作日志记录-测试多线程")
    @GetMapping("/getUserLogList")
    public R<List<UserLogRecord>>getUserLogList() throws ExecutionException, InterruptedException {
        return  userLogRecordService.getUserLogList();
    }

    /**
     * 模拟多线程情况下物品超扣问题-测试多线程
     */
    @ApiOperation(value = "同步锁的实际应用", notes = "同步锁的实际应用")
    @GetMapping("/shopping")
   public R<String> shopping(){
       return productsService.shopping();
   }
     /**
     * 模拟多线程情况下物品超扣问题-测试多线程
     */
     @ApiOperation(value = "分步式锁的实际应用", notes = "分步式锁的实际应用")
     @GetMapping("/shopping2")
      public R<String> shopping2() throws InterruptedException {
         return productsService.shopping2();
     }
    /**
     * Redisson分布式锁实现
     */
    @ApiOperation(value = "Redisson分布式锁实现", notes = "Redisson分布式锁实现")
    @GetMapping("/redissonLock")
    public R<String> redissonLock() throws InterruptedException {
        return productsService.redissonLock();
    }

}
